package tr.helper.controller.log;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import javafx.scene.control.cell.TextFieldListCell;
import javafx.scene.image.ImageView;
import tr.helper.controller.SecurityController;

public class LogController extends SecurityController {

    private ObservableList items = FXCollections.observableArrayList();

    @FXML
    private ListView<String> listLog;

    @FXML
    private ImageView codeImg;

    public void addLog(String msg, Object... args) {
        Platform.runLater(() -> {
            items.add(String.format(msg, args));
            listLog.setItems(items);
        });
    }

    public void addLog2(String msg, ImageView imageView) {
        Platform.runLater(() -> {
            if (null != imageView) {
                codeImg.setImage(imageView.getImage());
            }
            items.add(msg);
            listLog.setItems(items);
        });
    }

    @Override
    public void init(URL location, ResourceBundle resources) {
        listLog.setEditable(true);
        listLog.setCellFactory(TextFieldListCell.forListView());
    }

    @FXML
    public void doClear() {
        Platform.runLater(() -> {
            items.clear();
            listLog.getItems().clear();
        });

    }

}
